package com.zzld.modules.autoinn.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.abel533.entity.Example;
import com.zzld.core.service.BaseServiceImpl;
import com.zzld.modules.autoinn.entity.ProductPath;
import com.zzld.modules.autoinn.mapper.ProductPathMapper;
import com.zzld.modules.autoinn.service.IPathService;
import com.zzld.modules.common.dto.TreeGrid;

@Service("pathService")
public class PathServiceImpl extends BaseServiceImpl<ProductPath>  implements IPathService {

	@Autowired
	private ProductPathMapper productpathMapper;

	/**
	 * 获取树形网格
	 * 
	 * @return
	 */
	public List<TreeGrid> treeGrid() {
		List<TreeGrid> treeGrids = new ArrayList<TreeGrid>();
		Example d = new Example(ProductPath.class);
		List<ProductPath> listRes = productpathMapper
				.selectByExample(d);
		if (listRes != null && listRes.size() > 0) {
			for (ProductPath res : listRes) {
				TreeGrid treeGrid = new TreeGrid();
				BeanUtils.copyProperties(res, treeGrid);
				treeGrid.setText(res.getPathname());
				treeGrid.setCreateDate(res.getCreate_date());
				treeGrids.add(treeGrid);
			}
		}
		return treeGrids;
	}

	public List<ProductPath> selectbypid(String pid) {
		try {
			return productpathMapper.selectbypid(pid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;

	}

}
